<?php

class StatistikaModel extends NObject
{
	private $table = 'dbo.Statistiky';
	private $pozice = 'dbo.Pozice_Statistiky';
	private $zapas = 'dbo.Zapas_Statistiky';
	private $connection;


	public static function initialize()
	{
		dibi::connect(NEnvironment::getConfig('database'));
	}
	
	public function __construct()
	{
		$this->connection = dibi::getConnection();
	}
	//-----------
	//FIND ALL
	//-----------	
	public function findAll()
	{
		return $this->connection->select('*')->from($this->table);
	}
	//-----------
	//FIND BY ID
	//-----------
	public function findById($id)
	{
		return $this->connection->query("SELECT [*] FROM ".$this->table." WHERE id=%i",$id);
		//return $this->connection->select('*')->from($this->table)->where('id=%i',$id);
	}

	//-----------
	//UPDATE
	//-----------
	public function update($id, array $data)
	{
		return $this->connection->update($this->table, $data)->where('id=%i', $id)->execute();
	}
	//-----------
	//INSERT
	//-----------	
	public function insert(array $data)
	{
		return $this->connection->insert($this->table, $data)->execute(dibi::IDENTIFIER);
	}
	//-----------
	//FIND ALL
	//-----------
	public function delete($id)
	{
		return $this->connection->query("DELETE FROM ".$this->table." WHERE id=%i", $id);
		//return $this->connection->delete($this->table)->where('id=%i', $id)->execute();
	}

	/* POZICE */
	public function pozice_statistiky_findAll()
	{
		return $this->connection->select('*')->from($this->pozice);
	}
	public function pozice_statistiky_findById($id)
	{
		return $this->connection->query("SELECT [*] FROM ".$this->pozice." WHERE id=%i",$id);
	}
	public function pozice_statistiky_delete($id)
	{
		return $this->connection->query("DELETE FROM ".$this->pozice." WHERE id=%i", $id);
	}
	public function pozice_statistiky_update($id, array $data)
	{
		return $this->connection->update($this->pozice, $data)->where('id=%i', $id)->execute();
	}
	public function pozice_statistiky_insert(array $data)
	{
		return $this->connection->insert($this->pozice, $data)->execute(dibi::IDENTIFIER);
	}
	
	/* STATISTIKA */
	public function zapas_statistiky_findAll()
	{
		return $this->connection->select('*')->from($this->zapas);
	}
	public function zapas_statistiky_findById($id)
	{
		return $this->connection->query("SELECT [*] FROM ".$this->zapas." WHERE id=%i",$id);
	}
	public function zapas_statistiky_findByZapasId($id)
	{
		return $this->connection->query("SELECT [*] FROM ".$this->zapas." WHERE zapas_id=%i",$id);
	}
	public function zapas_statistiky_delete($id)
	{
		return $this->connection->query("DELETE FROM ".$this->zapas." WHERE id=%i", $id);
	}
	public function zapas_statistiky_update($id, array $data)
	{
		return $this->connection->update($this->zapas, $data)->where('id=%i', $id)->execute();
	}
	public function zapas_statistiky_insert(array $data)
	{
		return $this->connection->insert($this->zapas, $data)->execute(dibi::IDENTIFIER);
	}

}
